package com.yonyou.brigade.third_parties.ctrip.bigcustomer.controller;


import com.yonyou.brigade.basic_init.enums.ChannelEnum;
import com.yonyou.brigade.basic_init.service.IBriChannelService;
import com.yonyou.brigade.third_parties.ctrip.bigcustomer.service.ICtripBigUserService;
import com.yonyou.brigade.third_parties.ctrip.bigcustomer.util.CtripBigCustomerRMIUtils;
import com.yonyou.brigade.third_parties.ctrip.model.CtripConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jiangzhf@yonyou.com
 * @since 2018-08-17
 */
@Controller
@RequestMapping("/thirdparties/ctrip/bigcustomer/ctripBCUser")
public class CtripBigUserController {


    @Autowired
    @Qualifier("ctripBigUserServiceImpl")
    private ICtripBigUserService ctripBigUserService;


    @Autowired
    @Qualifier("briChannelServiceImpl")
    private IBriChannelService briChannelService;



    Logger logger=LoggerFactory.getLogger(CtripBigUserController.class);

    @RequestMapping(value = "/syncBigUser", method = RequestMethod.POST)
    public
    @ResponseBody void
    syncBigUser(@RequestBody Map params)
    {
        String tenant=params.get("tenant").toString();
        String orgPk=params.get("orgPk").toString();
        ctripBigUserService.syncCtripBigUsers(tenant,orgPk);
        return ;
    }

    @RequestMapping(value = "/ssomobilectrip", method = RequestMethod.GET)
    public void ssoMobileCtrip(String pCode,String orgPk, String tenant, String initPage, HttpServletResponse response) {

        int tokenType=1;
        try {
            CtripConfig config=(CtripConfig) briChannelService.getChannelConfig(tenant,ChannelEnum.CTRIPBC.getName(),orgPk,new CtripConfig());
            CtripBigCustomerRMIUtils.ssoMobileLogin(pCode,config, initPage, tokenType, response);
        }
        catch (Exception e)
        {
            logger.error(e.getMessage());
        }
    }

}

